list-[id].vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation1></HomePageNavigation1>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 二级标题-->
  10. <HomeListSecondaryHeading v-if="parent_name != ''" :name="parent_name" :nav="secondNav" :pinyin="parent_pinyin">
  11. </HomeListSecondaryHeading>
  12. <!-- 资讯列表 -->
  13. <div class="newsList">
  14. <div class="inner">
  15. <div class="innerLeft">
  16. <!-- 面包屑导航 -->
  17. <div class="breadcrumb phone_none">
  18. <div class="inner">
  19. <span class="location">当前位置:</span>
  20. <el-breadcrumb :separator-icon="ArrowRight">
  21. <el-breadcrumb-item>
  22. <NuxtLink to="/">首页</NuxtLink>
  23. </el-breadcrumb-item>
  24. <el-breadcrumb-item v-if="parent_name != ''">
  25. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  26. </el-breadcrumb-item>
  27. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  28. </el-breadcrumb>
  29. </div>
  30. </div>
  31. <div class="breadcrumb_box pc_none">
  32. <span class=" ">当前位置:</span>
  33. <NuxtLink to="/">首页</NuxtLink>
  34. <span class=" ">&gt;</span>
  35. <NuxtLink
  36. v-if="parent_name != ''"
  37. :to="`/${parent_pinyin}/index.html`">
  38. {{ parent_name }}
  39. </NuxtLink>
  40. <span class=" " v-if="parent_name != ''" >&gt;</span>
  41. <span class=" " >{{ name }}</span>
  42. </div>
  43. <ul class="list">
  44. <li v-for="(item, index) in newsList" :key="index">
  45. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  46. <span class="listTitle">{{ item.title }}</span>
  47. <span class="time">{{ getTime(item.updated_at, 'month', 1) }}</span>
  48. </NuxtLink>
  49. </li>
  50. </ul>
  51. <!-- 分页器 pc-->
  52. <div class="pagination pagination_phone_none" v-if="total > 0">
  53. <el-pagination size="small" background layout="prev, pager, next" :total="total" class="mt-4"
  54. :page-size="pageSize" :current-page="pageNum" prev-text="上一页" next-text="下一页"
  55. @current-change="changePage" />
  56. </div>
  57. <!-- 分页器 phone -->
  58. <div class="pagination pagination_pc_none" v-if="total > 0">
  59. <el-pagination
  60. size="small"
  61. background
  62. layout=" pager " :total="total" class="mt-4"
  63. :page-size="pageSize" :current-page="pageNum"
  64. @current-change="changePage" />
  65. </div>
  66. </div>
  67. <div class="innerRight">
  68. <DetailHotNews></DetailHotNews>
  69. <DetailHotNews2></DetailHotNews2>
  70. </div>
  71. </div>
  72. </div>
  73. <!-- 列表页广告二 -->
  74. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  75. <!-- 页面底部 -->
  76. <HomeFoot1></HomeFoot1>
  77. </div>
  78. </template>
  79. <script setup>
  80. //1.页面必备依赖 start ---------------------------------------->
  81. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus';
  82. import { ArrowRight } from '@element-plus/icons-vue';
  83. import { ref, onMounted } from 'vue';
  84. //1.页面必备依赖 end ---------------------------------------->
  85. //2.页面路径 start ---------------------------------------->
  86. const route = useRoute();
  87. let articleId = 0; //获取哪个导航下的列表
  88. //2.1 获得当前的完整路径
  89. const targetSegment = getRoutePath(1);
  90. //通过导航路径反向查询导航id
  91. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  92. method: 'GET',
  93. query: {
  94. 'pinyin': targetSegment,
  95. },
  96. });
  97. if (getRouteId.code == 200) {
  98. articleId = getRouteId.data.category_id
  99. } else {
  100. console.log("错误位置:获得页面路径")
  101. }
  102. //2.页面路径 end ---------------------------------------->
  103. //3.页面数据 start ---------------------------------------->
  104. let pageNum = ref(2); //当前页码
  105. pageNum.value = parseInt(route.params.id);//路由中传递的分页页码
  106. let total = ref(1); //总条数
  107. let pageSize = ref(20); //每页条数
  108. //3.1 新闻列表
  109. const newsList = ref([]);
  110. let newslists = async () => {
  111. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  112. method: 'GET',
  113. query: {
  114. 'page': pageNum.value,
  115. 'pageSize': pageSize.value,
  116. 'catid': articleId
  117. },
  118. });
  119. if (listData.code == 200) {
  120. newsList.value = listData.data.rows;
  121. total.value = listData.data.count;
  122. } else {
  123. console.log("错误位置:获取新闻列表")
  124. }
  125. }
  126. //获得列表
  127. newslists();
  128. //3.2 分页事件
  129. let changePage = (value) => {
  130. console.log("当前页码", value);
  131. navigateTo(`/${targetSegment}/list-${value}.html`)
  132. }
  133. //3.页面数据 end ---------------------------------------->
  134. //4.面包屑 start ---------------------------------------->
  135. const name = ref('')
  136. //4.1 当前频道名称
  137. let getPageName = async () => {
  138. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  139. method: 'GET',
  140. query: {
  141. 'catid': articleId
  142. },
  143. });
  144. if (pageName.code == 200) {
  145. name.value = pageName.data.alias
  146. } else {
  147. console.log("错误位置:获取当前频道名称", pageName.message)
  148. }
  149. }
  150. getPageName();
  151. //4.2 查询是否含有父级导航
  152. const parent_name = ref([]);
  153. const parent_id = ref([]);
  154. const parent_pinyin = ref("");
  155. let getParentNav = async () => {
  156. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  157. method: 'GET',
  158. query: {
  159. 'catid': articleId
  160. },
  161. });
  162. if (listData.code == 200) {
  163. parent_name.value = listData.data.parent_name;
  164. parent_id.value = listData.data.parent_id;
  165. parent_pinyin.value = listData.data.parent_pinyin;
  166. } else {
  167. console.log("错误位置:查询父级导航信息")
  168. }
  169. getSecondNav();
  170. }
  171. getParentNav();
  172. //4.3 获取二级栏目列表
  173. const secondNav = ref([]);
  174. let getSecondNav = async () => {
  175. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  176. method: 'GET',
  177. query: {
  178. 'placeid': 1,
  179. 'pid': parent_id.value,
  180. 'num': 8,
  181. },
  182. });
  183. console.log('listData', listData);
  184. if (listData.code == 200) {
  185. secondNav.value = listData.data
  186. } else {
  187. console.log("错误位置:获得二级栏目列表")
  188. }
  189. }
  190. //4.面包屑 end ---------------------------------------->
  191. //5.设置seo信息 start---------------------------------------->
  192. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  193. method: 'GET',
  194. query: {
  195. 'catid': articleId
  196. },
  197. });
  198. if (setData.code == 200) {
  199. let seoTitle = setData.data.seo_title;
  200. let seoDescription = setData.data.seo_description;
  201. let seoKeywords = setData.data.seo_keywords;
  202. let seoSuffix = setData.data.suffix;
  203. let seoName = setData.data.website_name;
  204. useSeoMeta({
  205. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  206. meta: [
  207. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  208. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
  209. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  210. ]
  211. });
  212. } else {
  213. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  214. // console.log("错误位置:设置列表页面SEO数据")
  215. // console.log("后端错误反馈:", setData.message)
  216. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  217. }
  218. //5.设置seo信息 end---------------------------------------->
  219. //6.广告 start---------------------------------------->
  220. let adImg1 = ref({});
  221. let adImg2 = ref({});
  222. onMounted(async () => {
  223. //从客户端获取行政职能部门 加快打开速度
  224. const { $webUrl, $CwebUrl } = useNuxtApp();
  225. //广告1
  226. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_list_0001`
  227. const responseAd1 = await fetch(url, {
  228. headers: {
  229. 'Content-Type': 'application/json',
  230. 'Userurl': $CwebUrl,
  231. 'Origin': $CwebUrl
  232. }
  233. });
  234. const resultAd1 = await responseAd1.json();
  235. adImg1.value = resultAd1.data[0];
  236. //广告2
  237. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=nmw_list_0002`
  238. const responseAd2 = await fetch(url2, {
  239. headers: {
  240. 'Content-Type': 'application/json',
  241. 'Userurl': $CwebUrl,
  242. 'Origin': $CwebUrl
  243. }
  244. });
  245. const resultAd2 = await responseAd2.json();
  246. adImg2.value = resultAd2.data[0];
  247. })
  248. //6.广告 end---------------------------------------->
  249. </script>
  250. <style lang="less" scoped>
  251. @import url('@/assets/css/list.less');
  252. </style>
  253. <style lang="less" scoped>
  254. @media screen and (min-width:801px){/*pc*/
  255. .pagination_pc_none{display:none!important;}
  256. .pc_none{display:none;}
  257. }
  258. @media screen and (max-width:800px){/*ipad_phone*/
  259. .newsList .inner{width:92%;margin:0px auto;}
  260. .newsList .inner .innerLeft{width:100%;margin:0px auto;float:none;}
  261. .breadcrumb_box{
  262. height:22px;width:100%;margin:10px auto;
  263. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  264. font-size:14px;
  265. color:#666;
  266. *{
  267. font-size:14px;
  268. display:inline ;
  269. color:#666;
  270. line-height:22px;height:22px;
  271. margin-right:5px;
  272. }
  273. }
  274. .newsList .inner .innerLeft .list{border-top:solid 1px #dd7d18;padding-top:10px;margin-bottom:10px;}
  275. .newsList .inner .innerLeft .list li{padding:0!important;}
  276. .newsList .inner .innerLeft .list > li:nth-child(5n){padding-bottom:11px!important;margin-bottom:11px;}
  277. .newsList .inner .innerLeft .list li a{display:block;height:40px;line-height:40px;}
  278. .newsList .inner .innerLeft .list li .listTitle{display:block;width:100%;height:100%;line-height:40px;
  279. font-weight:normal!important;font-size:16px;color:#333;
  280. }
  281. .newsList .inner .innerLeft .list li .time{display:none;}
  282. .newsList .inner .innerRight {display:none;}
  283. .newsList .inner .innerLeft > .pagination{width:100%;}
  284. .newsList{margin-bottom:22px;}
  285. .pagination_phone_none{display:none!important;}
  286. .phone_none{display:none;}
  287. }
  288. </style>